LOC_PATH="/apps/etc/"
USB_PATH="/media/usb/"

RESULT="/media/usb/Serial_Success"

ARGENTD_CFG="argentd.conf"
NPED_CFG="nped.conf"
SSLD_CFG="ssld.conf"
SYS_CFG="system.conf"
NET_CFG="network.cfg"

ALL_F="VERSION_COMPARE"

TPM_F="/tmp/VERSION_COMPARE"

osver > $TPM_F
fsver >> $TPM_F
/apps/netrouter/bin/netrouter --version >> $TPM_F
/apps/netcluster/netcluster --version >> $TPM_F
head -9 /logs/appweb.log >> $TPM_F
/apps/xmpp/xmpp --version >> $TPM_F

RET_1=`diff $LOC_PATH$ARGENTD_CFG $USB_PATH$ARGENTD_CFG -q`
RET_2=`diff $LOC_PATH$NPED_CFG    $USB_PATH$NPED_CFG    -q`
RET_3=`diff $LOC_PATH$SSLD_CFG    $USB_PATH$SSLD_CFG    -q`
RET_4=`diff $LOC_PATH$SYS_CFG     $USB_PATH$SYS_CFG     -q`
RET_5=`diff $LOC_PATH$NET_CFG     $USB_PATH$NET_CFG     -q`
RET_6=`diff $TPM_F                $USB_PATH$ALL_F       -q`

if [ "" == "$RET_1" -a "" == "$RET_2" -a "" == "$RET_3" -a "" == "$RET_4" -a "" == "$RET_5" -a "" == "$RET_6" ];then
	echo ""
	echo ""
	echo ""
	echo "update OK"
	echo ""
	echo ""
	echo ""
else
	echo ""
	echo ""
	echo ""
	echo "------------------------- update ERROR -------------------------"
	comport -ioctl /dev/beep 1 0
	echo ""
	echo ""
	echo ""
	exit 1
fi


SERIAL_FROM_EEP=`cat /tmp/device | grep "SerialNum" | awk -F '=' '{print $2}'`
SERIAL_FROM_SAM=`cat /logs/netcluster.log  | grep "@0668 Loaded certificate," | awk -F '/' '{print $6}' |  awk -F '=' '{print $2}'`

if [ "$SERIAL_FROM_EEP" == "$SERIAL_FROM_EEP" ];then
	echo ""
	echo ""
	echo ""
	echo "SAM OK"
	echo ""
	echo ""
	echo ""
else
	echo ""
	echo ""
	echo ""
	echo "------------------------- SAM ERROR -------------------------"
	comport -ioctl /dev/beep 1 0
	echo ""
	echo ""
	echo ""
	exit 1
fi

echo $SERIAL_FROM_EEP >> $RESULT
echo ""        
echo ""                                          
echo ""                                        
echo " *** *** Finish Successful *** *** "          
echo ""                            
echo ""
echo ""                                  
comport -ioctl /dev/beep 1 0
sleep 1                           
comport -ioctl /dev/beep 0 0
sleep 1        
comport -ioctl /dev/beep 1 0
sleep 1                 
comport -ioctl /dev/beep 0 0
sleep 1        
comport -ioctl /dev/beep 1 0
sleep 1
comport -ioctl /dev/beep 0 0
